package yzy.ecps.utils;

import java.util.List;

public class PageInfo {
	
	public PageInfo(){}
	
	public PageInfo(int totalCount){
		this.totalCount = totalCount;
	}
	public PageInfo(int totalCount,int pageSize){
		this.totalCount = totalCount;
		this.pageSize = pageSize;
	}
	
	private int totalCount;
	private int pageSize = 5;
	private int pageIndex = 1;
	@SuppressWarnings("unused")
	private int totalPage;
	@SuppressWarnings("unused")
	private int startNum;
	@SuppressWarnings("unused")
	private int endNum;
	
	private List<?> list;
	
	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
		setPageIndex(getPageIndex());
	}

	public int getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		int n = this.getTotalPage();
		if(pageIndex <= 0){
			this.pageIndex = 1;
		}
		else if(pageIndex > n)
			this.pageIndex = getTotalPage();
		else
			this.pageIndex = pageIndex;
	}

	public int getTotalPage() {
		if(getTotalCount() == 0) return 0;
		int n = getTotalCount()%getPageSize();
		return n == 0 ? getTotalCount()/getPageSize() : getTotalCount()/getPageSize() +1;
	}


	public int getStartNum() {
		return (getPageIndex()-1)*getPageSize();
	}


	public int getEndNum() {
		return getStartNum() + getPageSize() - 1;
	}

	public List<?> getList() {
		return list;
	}

	public void setList(List<?> list) {
		this.list = list;
	}
	
}
